home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rwvector.lha / RWVector2.1 / src / xgematio.cc < prev    next >
C/C++ Source or Header  |  1989-08-18  |  3KB  |  121 lines

  1. /*
  2.  *    Definitions for <A>GEMatrix I/O
  3.  *
  4.  *    Copyright (C) 1988, 1989.
  5.  *
  6.  *    Dr. Thomas Keffer
  7.  *    Rogue Wave Associates
  8.  *    P.O. Box 85341
  9.  *    Seattle WA 98145-1341
  10.  *
  11.  *    Permission to use, copy, modify, and distribute this
  12.  *    software and its documentation for any purpose and
  13.  *    without fee is hereby granted, provided that the
  14.  *    above copyright notice appear in all copies and that
  15.  *    both that copyright notice and this permission notice
  16.  *    appear in supporting documentation.
  17.  *    
  18.  *    This software is provided "as is" without any
  19.  *    expressed or implied warranty.
  20.  *
  21.  *
  22.  *    @(#)xgematio.cc    2.1    8/18/89
  23.  */
  24.  
  25. #define NO_VECTOR_MATHFUN
  26. #include "rw/<A>GEMatrix.h"
  27. #include <stream.h>
  28.  
  29. ostream&
  30. operator<<(ostream& s, const <A>GEMatrix& m)
  31. {
  32.   for (register int i=0; i< m.rows(); i++){
  33.     for (register int j = 0; j < m.cols(); j++) s << m(i,j) << " ";
  34.     s << NL;
  35.   }
  36.   return s;
  37. }
  38.  
  39. void
  40. <A>GEMatrix::assertRowRange(int i)
  41. {
  42.   if(i < 0 || i >= nrows){
  43.     char msg[120];
  44.     sprintf(msg, "Row index (%d) out of range [0->%d].", i, nrows-1);
  45.     RWnote("<A>GEMatrix::assertRowRange()", msg);
  46.     RWerror(DEFAULT);
  47.   }
  48. }
  49.  
  50. void
  51. <A>GEMatrix::assertColRange(int j)
  52. {
  53.   if(j < 0 || j >= ncols){
  54.     char msg[120];
  55.     sprintf(msg, "Column index (%d) out of range [0->%d].", j, ncols-1);
  56.     RWnote("<A>GEMatrix::assertColRange()", msg);
  57.     RWerror(DEFAULT);
  58.   }
  59. }
  60.  
  61. void
  62. <A>GEMatrix::assertRowCol(const <A>GEMatrix& m)
  63. {
  64.   if(m.nrows != nrows || m.ncols != ncols){
  65.     char msg[120];
  66.     sprintf(msg, "Rows/Columns do not match: (%d, %d) versus (%d, %d)",
  67.         nrows, ncols, m.nrows, m.ncols);
  68.  
  69.     RWnote("<A>GEMatrix::assertRowCol()", msg);
  70.     RWerror(DEFAULT);
  71.   }
  72. }
  73.  
  74. void
  75. <A>GEMatrix::assertLength(const <T>Vec& v)
  76. {
  77.   if(nrows*ncols != v.length()){
  78.     char msg[120];
  79.     sprintf(msg, "Vector length (%d) does not match rows and columns (%d, %d)",
  80.         v.length(), nrows, ncols);
  81.  
  82.     RWnote("<A>GEMatrix::assertLength()", msg);
  83.     RWerror(DEFAULT);
  84.   }
  85. }
  86.  
  87. void
  88. <A>GEMatrix::assertSquare()
  89. {
  90.   if(nrows != ncols){
  91.     char msg[120];
  92.     sprintf(msg, "Matrix (%d by %d) is not square", nrows, ncols);
  93.     RWnote("<A>GEMatrix::assertSquare()", msg);
  94.     RWerror(DEFAULT);
  95.   }
  96. }
  97.  
  98. void
  99. <A>GEMatrix::assertProduct(const <A>GEMatrix& m)
  100. {
  101.   if(ncols!=m.nrows){
  102.     char msg[120];
  103.     sprintf(msg, "Inner product not possible between (%d by %d) and (%d by %d)",
  104.         nrows, ncols, m.nrows, m.ncols);
  105.     RWnote("<A>GEMatrix::assertProduct()", msg);
  106.     RWerror(DEFAULT);
  107.   }
  108. }
  109.  
  110. void
  111. <A>GEMatrix::assertProduct(const <T>Vec& v)
  112. {
  113.   if(ncols!=v.length()){
  114.     char msg[120];
  115.     sprintf(msg, "Inner product not possible between matrix %d by %d and vector %d points long",
  116.         nrows, ncols, v.length());
  117.     RWnote("<A>GEMatrix::assertProduct()", msg);
  118.     RWerror(DEFAULT);
  119.   }
  120. }
  121.